# -*- coding:utf-8 -*-

# @Time : 2023/3/27 18:41
# @Author : 快乐的小猴子
# @Version : 
# @Function : 

import requests
from lxml import etree
import asyncio


async def get_data(url):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
    }
    resp = requests.get(url, headers=headers).content.decode()
    tree = etree.HTML(resp)
    app_name = tree.xpath('//ul[@class="applist"]/li/h5/a/text()')
    app_url = tree.xpath('//ul[@class="applist"]/li/h5/a/@href')
    for i in range(0, len(app_name)):
        name = app_name[i]
        url = 'https://app.mi.com/' + app_url[i]
        print(name, url)


if __name__ == '__main__':

    for i in range(1, 4):
        url = 'https://app.mi.com/catTopList/0?page={}'.format(i)
        cor = get_data(url)
        task = asyncio.ensure_future(cor)
        loop = asyncio.get_event_loop()
        loop.run_until_complete(task)
